package com.cloud.school.bus.teacherhelper.protocol.statistics;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Random;

import android.content.Context;
import android.text.TextUtils;

import com.android.support.jhf.debug.DebugLog;
import com.android.support.jhf.network.loopj.android.http.RequestParams;
import com.cloud.school.bus.teacherhelper.protocol.ProtocolDef;
import com.cloud.school.bus.teacherhelper.protocol.baserequest.BasePostHttpRequest;

/**
 * 上传图片和视频
 * 
 * @author jiahongfei
 * 
 */
public class UploadFileRequest extends BasePostHttpRequest {

	/**
	 * 上传图片和视频
	 * 
	 * @param context
	 * @param fbody
	 *            文件
	 * @param pictype
	 *            传article
	 * @param fname
	 *            文件名
	 * @param memberlist
	 *            学生id 以,分割
	 * @param ftime
	 *            图片的时间
	 * @param uid
	 *            班级uid
	 * @param intro
	 *            内容
	 * @param tag
	 *            标签
	 * @param teacherid
	 *            上传者老师id
	 * @param pickey
	 *            开发者生成唯一的key
	 * @param ftime
	 * 			 图片的创建时间
	 */
	public UploadFileRequest(Context context, String fbody, String fname,
			String memberlist, String uid, String intro, String tag,
			String teacherid,String ftime) {
		super(context);

		mMethod = ProtocolDef.METHOD_Source;
		mRequestParams = new RequestParams();
		try {
			mRequestParams.put("fbody", new File(fbody));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		mRequestParams.put("pictype", "article");
		if (!TextUtils.isEmpty(fname)) {
			mRequestParams.put("fname", fname);
		}
		if (!TextUtils.isEmpty(memberlist)) {
			mRequestParams.put("memberlist", memberlist);
		}
		if(!TextUtils.isEmpty(ftime)){
			mRequestParams.put("ftime", ftime);
		}
//		mRequestParams.put("ftime", (System.currentTimeMillis() / 1000) + "");
		if (!TextUtils.isEmpty(uid)) {
			mRequestParams.put("uid", uid);
		}
		if (!TextUtils.isEmpty(intro) && !"null".equals(intro)) {
			mRequestParams.put("intro", intro);
		}
		if (!TextUtils.isEmpty(tag) && !"null".equals(tag)) {
			mRequestParams.put("tag", tag);
		}
		if (!TextUtils.isEmpty(teacherid)) {
			mRequestParams.put("teacherid", teacherid);
		}
		mRequestParams.put("pickey",
				(System.currentTimeMillis() + new Random().nextInt(1000)) + "");
		
		DebugLog.logI("mMethod : " + mMethod + " RequestParams : " + mRequestParams.toString());
	}

	@Override
	public String getAbsoluteUrl() {
		return "http://client.yunxiaoche.com/" + mMethod;
	}

}
